#include "widget.h"
#include "ui_widget.h"
#include <QPixmap>
#include <QIcon>
#include <QMessageBox>
#include <QMenu>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPixmap pix;
    ui->toolButton->setIconSize(QSize(58, 58));
    pix.load(":/res/auto_color_auto_start.png");
    ui->toolButton->setIcon(QIcon(pix));
    ui->toolButton->setStyleSheet("QToolButton{font:13pt;color:white;background-color:transparent;border:none;border-radius:0px;}");


    ui->pushButton->setIconSize(QSize(58, 58));
    pix.load(":/res/dst_direction_1.png");
    ui->pushButton->setIcon(QIcon(pix));
    ui->pushButton->setStyleSheet("QToolButton{font:13pt;color:white;background-color:blue;border:none;border-radius:0px;}");

    QMenu *pMenu = new QMenu();
    if(pMenu)
    {
        ui->menuTB->setMenu(pMenu);
        pMenu->addAction("第一个菜单", this, SLOT(firstToolButtonMenu()));
        pMenu->addAction("第二个菜单", this, SLOT(secondToolButtonMenu()));
        pMenu->addAction("第三个菜单", this, SLOT(thirdToolButtonMenu()));
    }

}

Widget::~Widget()
{
    QMenu *pMenu = ui->menuTB->menu();
    if(pMenu)
    {
        delete pMenu;
    }
    delete ui;
}

void Widget::firstToolButtonMenu()
{
    QMessageBox msgBox;
    msgBox.setText("第一个菜单");
    msgBox.exec();
}

void Widget::secondToolButtonMenu()
{
    QMessageBox msgBox;
    msgBox.setText("第二个菜单");
    msgBox.exec();
}

void Widget::thirdToolButtonMenu()
{
    QMessageBox msgBox;
    msgBox.setText("第三个菜单");
    msgBox.exec();
}
